<template>
  <a-modal
    title="查看岗位"
    :width="1010"
    :visible="visible"
    :confirmLoading="loading"
    @ok="() => { $emit('ok') }"
    @cancel="() => { $emit('cancel') }"
    footer="">
    <a-spin :spinning="loading">
      <a-form :form="form" v-bind="formLayout">
        <!-- 检查是否有 id 并且大于0，大于0是修改。其他是新增，新增不显示主键ID -->
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
              label="岗位名称"
              :labelCol="{lg: {span: 7}, sm: {span:7}}"
              :wrapperCol="{lg: {span: 17}, sm: {span: 17} }">
              <BaseInput
                v-decorator="[
              'jobName',{rules: [{  required: true, message: '请输入标题' }]}]"
                placeholder="输入岗位名称" disabled  />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
              label="岗位类型"
              :labelCol="{lg: {span: 7}, sm: {span: 7}}"
              :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <a-select disabled
              v-decorator="['jobType',{rules: [{ required: true, message: '' }]}]">
                <a-select-option value="领导班子">领导班子</a-select-option>
                <a-select-option value="其他岗位">其他岗位</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="所属部门"
                    :labelCol="{lg: {span: 7}, sm: {span:7}}"
                    :wrapperCol="{lg: {span: 17}, sm: {span: 17} }">
              <BaseInput v-decorator="['orgName',{rules: [{  required: true, message: ' ' }]}]" placeholder=""  disabled />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <!--<a-form-item-->
                    <!--label="岗位编码"-->
                    <!--:labelCol="{lg: {span: 7}, sm: {span:7}}"-->
                    <!--:wrapperCol="{lg: {span: 17}, sm: {span: 17} }">-->
              <!--<BaseInput v-decorator="['code',{rules: [{  required: true, message: '请输入' }]}]" placeholder=""  disabled />-->
            <!--</a-form-item>-->
            <a-form-item
                    label="岗位人数限制(土建)"
                    :labelCol="{lg: {span: 7}, sm: {span:7}}"
                    :wrapperCol="{lg: {span: 17}, sm: {span: 17} }">
              <a-select disabled v-decorator="['numberLimitEngineering',{rules: [{ required: true, message: ' ' }]}]">
                <a-select-option value="单人">单人</a-select-option>
                <a-select-option value="多人">多人</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!--<a-col :md="12" :sm="12">-->
            <!--<a-form-item-->
              <!--label="岗位人数限制(土建)"-->
              <!--:labelCol="{lg: {span: 7}, sm: {span:7}}"-->
              <!--:wrapperCol="{lg: {span: 17}, sm: {span: 17} }">-->
              <!--<a-select disabled v-decorator="['numberLimitEngineering',{rules: [{ required: true, message: ' ' }]}]">-->
                <!--<a-select-option value="单人">单人</a-select-option>-->
                <!--<a-select-option value="多人">多人</a-select-option>-->
              <!--</a-select>-->
            <!--</a-form-item>-->
          <!--</a-col>-->

        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="是否可兼任"
                    :labelCol="{lg: {span: 7}, sm: {span: 7}}"
                    :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <a-select disabled v-decorator="['canBothEngineering',{rules: [{ required: true, message: ' ' }]}]">
                <a-select-option value="不可兼任">不可兼任</a-select-option>
                <a-select-option value="可兼任">可兼任</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
              label="是否必填(土建)"
              :labelCol="{lg: {span: 7}, sm: {span:7}}"
              :wrapperCol="{lg: {span: 17}, sm: {span: 17} }">
              <a-select disabled v-decorator="['requiredEngineering',{rules: [{ required: true, message: ' ' }]}]">
                <a-select-option value="否">否</a-select-option>
                <a-select-option value="是">是</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
              label="岗位人数限制(专业)"
              :labelCol="{lg: {span: 7}, sm: {span:7}}"
              :wrapperCol="{lg: {span: 17}, sm: {span: 17} }">
              <a-select disabled v-decorator="['numberLimitProfession',{rules: [{ required: true, message: ' ' }]}]">
                <a-select-option value="单人">单人</a-select-option>
                <a-select-option value="多人">多人</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
              label="是否可兼任(专业)"
              :labelCol="{lg: {span: 7}, sm: {span: 7}}"
              :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <a-select disabled v-decorator="['canBothProfession',{rules: [{ required: true, message: ' ' }]}]">
                <a-select-option value="不可兼任">不可兼任</a-select-option>
                <a-select-option value="可兼任">可兼任</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
              label="是否必填(专业)"
              :labelCol="{lg: {span: 7}, sm: {span:7}}"
              :wrapperCol="{lg: {span: 17}, sm: {span: 17} }">
              <a-select disabled v-decorator="['requiredProfession',{rules: [{ required: true, message: ' ' }]}]">
              <a-select-option value="否">否</a-select-option>
                <a-select-option value="是">是</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!--<a-col :md="12" :sm="12">-->
            <!--<a-form-item-->
              <!--label="状态"-->
              <!--:labelCol="{lg: {span: 7}, sm: {span: 7}}"-->
              <!--:wrapperCol="{lg: {span:17}, sm: {span: 17} }">-->
              <!--<a-select disabled v-decorator="['jobStatus',{rules: [{ required: true, message: ' ' }]}]">-->
                <!--<a-select-option value="不可用">不可用</a-select-option>-->
                <!--<a-select-option value="可用">可用</a-select-option>-->
              <!--</a-select>-->
            <!--</a-form-item>-->
          <!--</a-col>-->
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'

// 表单字段
const fields = ['jobId','jobName','jobTypeCode','jobStatusCode','jobType','orgName','code','requiredEngineering','canBothEngineering','numberLimitEngineering','numberLimitProfession','canBothProfession','requiredProfession','jobStatus',
  'canBothProfessionCode','canBothEngineeringCode','numberLimitEngineeringCode','numberLimitProfessionCode','requiredEngineeringCode','requiredProfessionCode'
]

export default {
  name:'a'+Date.now(),
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    loading: {
      type: Boolean,
      default: () => false
    },
    model: {
      type: Object,
      default: () => null
    }
  },
  data () {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 }
      }
    }
    return {
      form: this.$form.createForm(this)
    }
  },
  created () {
    // 防止表单未注册
    fields.forEach(v => this.form.getFieldDecorator(v))

    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields))
    })
  },
  methods:{

  }
}
</script>
